<?php namespace Common\Model;
use Hdphp\Model\Model;

/*标签模型*/

class Tag extends Model
{
	/*写入表*/
	protected $table = "tag";
	/*自动验证*/
	protected $validate = array(
		array("tname","required","请输入标签",3,3),
		array("tname","max_len","做多输入20个字符",3,3),
	
	);
	/*添加标签*/
	public function store()
	{

		/*自动验证*/
		if(!$this->create()) return false;
		/*执行添加*/
		$tname = explode("|",$_POST['tname'] );
		foreach ($tname as $v) {
			$this->add(array("tname"=>$v));
		}
		return TRUE;
		
	}
	/*编辑*/
	public function edit()
	{
		/*自动验证*/
		if(!$this->create()) return false;
		/*执行修改*/
		return $this->save();
	}
	/*删除*/
	public function del($tid)
	{
	
		$this->where('tid',$tid)->delete();
		//实例化article_tag
		$arctagModel = new \Common\Model\ArticleTag;
		$arctagModel->where("tag_tid",$tid)->delete();
		
	}
}























